package com.ruoyi.weixin.mp.controller;

import java.util.Arrays;
import java.util.Map;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.weixin.mp.entity.MsgReplyRule;
import com.ruoyi.weixin.mp.service.MsgReplyRuleService;
import com.ruoyi.weixin.mp.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 自动回复规则
 *
 * @author niefy
 * @email niefy@qq.com
 * @date 2019-11-12 18:30:15
 */
@RestController
@RequestMapping("/manage/msgReplyRule")
@Api(tags = {"自动回复规则-管理后台"})
public class MsgReplyRuleManageController {

    @Autowired
    private MsgReplyRuleService msgReplyRuleService;

    @Autowired
    private WxMpService wxMpService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('wx:msgreplyrule:list')")
    @ApiOperation(value = "列表")
    public AjaxResult list(@RequestParam Map<String, Object> params) {
        PageUtils page = msgReplyRuleService.queryPage(params);
        return AjaxResult.success(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{ruleId}")
    @PreAuthorize("@ss.hasPermi('wx:msgreplyrule:info')")
    @ApiOperation(value = "详情")
    public AjaxResult info(@PathVariable("ruleId") Long ruleId) {
        MsgReplyRule msgReplyRule = msgReplyRuleService.getById(ruleId);
        return AjaxResult.success(msgReplyRule);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @PreAuthorize("@ss.hasPermi('wx:msgreplyrule:save')")
    @ApiOperation(value = "保存")
    public AjaxResult save(@RequestBody MsgReplyRule msgReplyRule) {
        msgReplyRuleService.save(msgReplyRule);
        return AjaxResult.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @PreAuthorize("@ss.hasPermi('wx:msgreplyrule:update')")
    @ApiOperation(value = "修改")
    public AjaxResult update(@RequestBody MsgReplyRule msgReplyRule) {
        msgReplyRuleService.updateById(msgReplyRule);
        return AjaxResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('wx:msgreplyrule:delete')")
    @ApiOperation(value = "删除")
    public AjaxResult delete(@RequestBody Integer[] ruleIds) {
        msgReplyRuleService.removeByIds(Arrays.asList(ruleIds));

        return AjaxResult.success();
    }

}
